package ch.elca.training.validator;

import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import ch.elca.training.dto.ProjectCriterionDto;

@Component
public class ProjectCriterionValidator implements Validator {

	@Override
	public boolean supports(Class<?> clazz) {
		return clazz.isAssignableFrom(ProjectCriterionDto.class);
	}

	@Override
	public void validate(Object target, Errors errors) {
		ProjectCriterionDto projectCriterionDto = (ProjectCriterionDto) target;
		if (projectCriterionDto.getCustomer() == null
				&& projectCriterionDto.getName() == null
				&& projectCriterionDto.getNumber() == null
				&& projectCriterionDto.getStatus() == null) {
			errors.rejectValue("errors.empty.type", "error", "all empty");
		}

	}

}
